﻿<phone:PhoneApplicationPage
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:controlsPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls"
    x:Class="AirportApp.MainPage"
    mc:Ignorable="d"
    d:DesignWidth="480"
    d:DesignHeight="768"
    SupportedOrientations="Portrait"
    Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    xmlns:data="clr-namespace:AirportApp.Data">
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate
            x:Key="AirportItemTemplate">
            <Grid
                Height="59"
                Width="403">
                <Grid.RowDefinitions>
                    <RowDefinition
                        Height="Auto"
                        MinHeight="123" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition
                        Width="0.275*" />
                    <ColumnDefinition
                        Width="0.725*" />
                </Grid.ColumnDefinitions>
                <TextBlock
                    Text="{Binding Code}"
                    FontSize="48" />
                <StackPanel
                    Grid.Column="1"
                    Margin="0,4,0,0">
                    <TextBlock
                        Text="{Binding Name}"
                        Grid.Column="1"
                        Margin="0" />
                    <TextBlock
                        Text="{Binding Country}"
                        Grid.Column="1"
                        Margin="0" />
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate
            x:Key="CountryItemTemplate">
            <StackPanel>
                <TextBlock
                    Text="{Binding Mode=OneWay}"
                    FontSize="48" />
            </StackPanel>
        </DataTemplate>

        <ItemsPanelTemplate
            x:Key="ItemsPanelTemplate1">
            <controlsPrimitives:PanoramaPanel
                x:Name="panel"
                Margin="0,-71,0,0" />
        </ItemsPanelTemplate>

        <data:AirportGroupToBackgroundBrushValueConverter
            x:Key="AirportGroupBackground" />
        <data:AirportGroupToForegroundBrushValueConverter
            x:Key="AirportGroupForeground" />

        <data:CountryGroupToBackgroundBrushValueConverter
            x:Key="CountryGroupBackground" />
        <data:CountryGroupToForegroundBrushValueConverter
            x:Key="CountryGroupForeground" />

    </phone:PhoneApplicationPage.Resources>
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar
            x:Name="_applicationBar"
            IsVisible="False"
            BackgroundColor="Black">
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem
                    x:Name="_settings"
                    IsEnabled="True"
                    Text="Settings" />

            </shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarIconButton
                x:Name="_searchButton"
                IconUri="/icons/appbar.feature.search.rest.png"
                IsEnabled="True"
                Text="search"
                Click="_searchButton_Click" />
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource
            ResourceKey="PhoneFontFamilyNormal" />
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource
            ResourceKey="PhoneFontSizeNormal" />
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource
            ResourceKey="PhoneForegroundBrush" />
    </phone:PhoneApplicationPage.Foreground>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid
        x:Name="LayoutRoot"
        Background="Transparent"
        DataContext="{Binding Source={StaticResource AirportViewModelDataSource}}">
        <Grid.RowDefinitions>
            <RowDefinition
                Height="768" />
        </Grid.RowDefinitions>

        <!--ContentPanel - place additional content here-->
        <controls:Panorama
            x:Name="_panorama"
            Title="{Binding Strings.AppTitle, Source={StaticResource StringHelper}}"
            ItemsPanel="{StaticResource ItemsPanelTemplate1}">
            <controls:Panorama.Background>
                <ImageBrush
                    Stretch="None" />
            </controls:Panorama.Background>
            <controls:PanoramaItem
                Header="{Binding Strings.Airport, Source={StaticResource StringHelper}}">
            	<Grid>
            		<toolkit:LongListSelector
            			x:Name="_airportListGrouped"
            			Background="Transparent"
            			Margin="0"
            			GroupViewOpened="LongListSelector_GroupViewOpened"
            			ItemsSource="{Binding AirportsInGroups}"
            			ItemTemplate="{StaticResource AirportItemTemplate}">
            			<toolkit:LongListSelector.GroupItemsPanel>
            				<ItemsPanelTemplate>
            					<toolkit:WrapPanel
            						Orientation="Horizontal" />
            				</ItemsPanelTemplate>
            			</toolkit:LongListSelector.GroupItemsPanel>

            			<toolkit:LongListSelector.GroupHeaderTemplate>
            				<DataTemplate>
            					<Border
            						Margin="12,8,0,8">
            						<Border
            							Background="{StaticResource PhoneAccentBrush}"
            							Padding="8,0,0,0"
            							Width="62"
            							Height="62"
            							HorizontalAlignment="Left">
            							<TextBlock
            								Text="{Binding Key}"
            								Foreground="#FFFFFF"
            								FontSize="48"
            								FontFamily="{StaticResource PhoneFontFamilySemiLight}"
            								HorizontalAlignment="Left"
            								VerticalAlignment="Bottom" />
            						</Border>
            					</Border>
            				</DataTemplate>
            			</toolkit:LongListSelector.GroupHeaderTemplate>

            			<toolkit:LongListSelector.GroupItemTemplate>
            				<DataTemplate>
            					<Border
            						Background="{Binding Converter={StaticResource AirportGroupBackground}}"
            						Width="99"
            						Height="99"
            						Margin="6"
            						IsHitTestVisible="{Binding HasItems}">
            						<Border.Projection>
            							<PlaneProjection
            								RotationX="-60" />
            						</Border.Projection>
            						<TextBlock
            							Text="{Binding Key}"
            							FontFamily="{StaticResource PhoneFontFamilySemiBold}"
            							FontSize="48"
            							Margin="8,0,0,0"
            							Foreground="{Binding Converter={StaticResource AirportGroupForeground}}"
            							VerticalAlignment="Bottom" />
            					</Border>
            				</DataTemplate>
            			</toolkit:LongListSelector.GroupItemTemplate>

            		</toolkit:LongListSelector>
            	</Grid>
            </controls:PanoramaItem>
            <controls:PanoramaItem
                Header="{Binding Strings.Country, Source={StaticResource StringHelper}}">
                <Grid>
                    <toolkit:LongListSelector
                        x:Name="_countryListGrouped"
                        Background="Transparent"
                        Margin="0"
                        GroupViewOpened="LongListSelector_GroupViewOpened"
                        ItemsSource="{Binding CountriesInGroups}"
                        ItemTemplate="{StaticResource CountryItemTemplate}">
                        <toolkit:LongListSelector.GroupItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel
                                    Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </toolkit:LongListSelector.GroupItemsPanel>

                        <toolkit:LongListSelector.GroupHeaderTemplate>
                            <DataTemplate>
                                <Border
                                    Margin="12,8,0,8">
                                    <Border
                                        Background="{StaticResource PhoneAccentBrush}"
                                        Padding="8,0,0,0"
                                        Width="62"
                                        Height="62"
                                        HorizontalAlignment="Left">
                                        <TextBlock
                                            Text="{Binding Key}"
                                            Foreground="#FFFFFF"
                                            FontSize="48"
                                            FontFamily="{StaticResource PhoneFontFamilySemiLight}"
                                            HorizontalAlignment="Left"
                                            VerticalAlignment="Bottom" />
                                    </Border>
                                </Border>
                            </DataTemplate>
                        </toolkit:LongListSelector.GroupHeaderTemplate>

                        <toolkit:LongListSelector.GroupItemTemplate>
                            <DataTemplate>
                                <Border
                                    Background="{Binding Converter={StaticResource CountryGroupBackground}}"
                                    Width="99"
                                    Height="99"
                                    Margin="6"
                                    IsHitTestVisible="{Binding HasItems}">
                                    <Border.Projection>
                                        <PlaneProjection
                                            RotationX="-60" />
                                    </Border.Projection>
                                    <TextBlock
                                        Text="{Binding Key}"
                                        FontFamily="{StaticResource PhoneFontFamilySemiBold}"
                                        FontSize="48"
                                        Margin="8,0,0,0"
                                        Foreground="{Binding Converter={StaticResource CountryGroupForeground}}"
                                        VerticalAlignment="Bottom" />
                                </Border>
                            </DataTemplate>
                        </toolkit:LongListSelector.GroupItemTemplate>

                    </toolkit:LongListSelector>
                </Grid>
            </controls:PanoramaItem>
            <!--
            <controls:PanoramaItem
                Header="{Binding Strings.Airport, Source={StaticResource StringHelper}}">
                <controls:PanoramaItem.Background>
                    <ImageBrush
                        Stretch="Fill" />
                </controls:PanoramaItem.Background>
                <Grid>
                    <ListBox
                        x:Name="_airportList"
                        ItemTemplate="{StaticResource AirportItemTemplate}"
                        ItemsSource="{Binding Airports}" />
                </Grid>
            </controls:PanoramaItem>
            <controls:PanoramaItem
                Header="{Binding Strings.Country, Source={StaticResource StringHelper}}">
                <Grid>
                    <ListBox
                        x:Name="_countryList"
                        ItemTemplate="{StaticResource CountryItemTemplate}"
                        ItemsSource="{Binding Countries}"
                        DoubleTap="_countryList_DoubleTap" />
                </Grid>
            </controls:PanoramaItem>
            -->
        </controls:Panorama>
        <TextBox
            x:Name="_search"
            TextWrapping="Wrap"
            VerticalAlignment="Top"
            Visibility="Collapsed" />
    </Grid>

</phone:PhoneApplicationPage>